//home模块的小仓库
import { reqCategoryList, reqGetBannerList, reqFloorsList } from '@/api';

// home模块的数据仓库
const state = {
  // state 中的数据默认初始值别瞎写,服务器返回的是对象,起始值就是对象,服务器返回啥类型起始值就是啥类型
  categoryList: [],
  bannerList: [],
  floorsList: [],
};

// mutations是唯一修改state的地方
const mutations = {
  CATEGORYLIST(state, categoryList) {
    categoryList.pop();
    state.categoryList = categoryList;
  },
  BANNERLIST(state, bannerList) {
    state.bannerList = bannerList;
  },
  FLOORSLIST(state, floorsList) {
    state.floorsList = floorsList;
  },
};

// 用户派发action的地方,可以书写一步语句.写自己的逻辑
const actions = {
  async categoryList({ commit }) {
    let result = await reqCategoryList();
    if (result.code == 200) {
      commit('CATEGORYLIST', result.data);
    }
  },
  async getBannerList({ commit }) {
    let result = await reqGetBannerList();
    if (result.code == 200) {
      commit('BANNERLIST', result.data);
    }
  },
  async getFloorsList({ commit }) {
    let result = await reqFloorsList();
    if (result.code == 200) {
      commit('FLOORSLIST', result.data);
    }
  },
};

// 计算属性
const getters = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
